package util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 我们自己定义的报文 ，响应报文
 *
 * @author qjw
 * @version 1.0
 * @date 2023/9/9 10:08
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "自定义响应报文")
public class RespMessUtil<E> {

    /**
     * 状态码
     */
    @ApiModelProperty(value = "状态码", required = true)
    private Integer code;

    /**
     * 提示信息
     */
    @ApiModelProperty(value = "提示信息", required = true)
    private String mess;

    /**
     * 影响结果
     */
    @ApiModelProperty(value = "影响结果", required = true)
    private E data;

    /**
     *
     * @param code  状态码
     * @param data  提示信息
     * @param <E>   影响结果
     * @return
     */
    public static <E> RespMessUtil<E> build(CodeStatusEnum code, E data) {
        RespMessUtil<E> respMess = new RespMessUtil<>();
        respMess.setCode(code.getCode());
        respMess.setMess(code.getDesc());
        respMess.setData(data);
        return respMess;
    }

    public static <E> RespMessUtil<E> build(CodeStatusEnum codeStatus, String mess) {
        RespMessUtil<E> respMess = new RespMessUtil<>();
        respMess.setCode(codeStatus.getCode());
        respMess.setMess(mess);
        return respMess;
    }


    /**
     * 添加成功
     * @return
     */
    public static RespMessUtil<Integer> insertOk() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.SUSSESS.getCode());
        respMess.setMess(ConstUtil.TIP_INSERT_SUCCESS);
        respMess.setData(1);
        return respMess;
    }

    /**
     * 添加失败
     * @return
     */

    public static RespMessUtil<Integer> insertFailure() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.FAILURE.getCode());
        respMess.setMess(ConstUtil.TIP_INSERT_FAILURE);
        return respMess;
    }

    /**
     * 更改成功
     * @return
     */

    public static RespMessUtil<Integer> updateOk() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.SUSSESS.getCode());
        respMess.setMess(ConstUtil.TIP_UPDATE_SUCCESS);
        respMess.setData(1);
        return respMess;
    }

    /**
     * 更改失败
     * @return
     */

    public static RespMessUtil<Integer> updateFailure() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.FAILURE.getCode());
        respMess.setMess(ConstUtil.TIP_UPDATE_FAILURE);
        return respMess;
    }


    /**
     * 删除成功
     * @return
     */
    public static RespMessUtil<Integer> deleteOk() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.SUSSESS.getCode());
        respMess.setMess(ConstUtil.TIP_DELETE_SUCCESS);
        respMess.setData(1);
        return respMess;
    }

    /**
     * 删除失败
     * @return
     */

    public static RespMessUtil<Integer> deleteFailure() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.FAILURE.getCode());
        respMess.setMess(ConstUtil.TIP_DELETE_FAILURE);
        return respMess;
    }




}
